import time
import hashlib


class UpApiClient(object):
    @classmethod
    def get_source(cls, parameters):
        """
        :param parameters:
        :return:
        """
        source = ""
        base_sorted = sorted(parameters)
        for i in base_sorted:
            source = source + str(i) + str(parameters[i])
        return source

    @classmethod
    def hashlib_md5(cls, parm):
        m2 = hashlib.md5()
        m2.update(parm.encode('utf-8'))
        return m2.hexdigest()

    def get_sign(self, parameters, app_secret):
        """
        获取签名
        :param parameters:
        :param app_secret:
        :return:
        """
        source = self.get_source(parameters)
        content = app_secret + source + app_secret
        sign = self.hashlib_md5(content)
        return sign


api_client = UpApiClient()
